package com.zl.learning.collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class TestHashMap {

    @Test
    public void test1() {
        Map<String, String> m1 = new HashMap<>(2);
        m1.put("c", "c");
        m1.put("a", "a");
        m1.put("b", "b");
        m1.put("F", "F");
    }

    @Test
    public void test2() {
        Map<String, List<String>> ms = new HashMap<>();
        List<String> l1 = new ArrayList<>();
        l1.add("a1");
        l1.add("a2");
        l1.add("a3");

        List<String> l2 = new ArrayList<>();
        l2.add("b1");
        l2.add("b2");
        l2.add("b3");

        List<String> l3 = new ArrayList<>();
        l3.add("c1");
        l3.add("c2");
        l3.add("c3");

        ms.put("l1", l1);
        ms.put("l2", l2);
        ms.put("l3", l3);
        final String[] key = {null};
        ms.entrySet().stream().filter(r -> r.getValue().contains("a1")).findAny().ifPresent(r -> key[0] = r.getKey());
        System.out.println(key[0]);

        Stream.of("l1", "l2").filter(ms::containsKey).flatMap(r -> ms.get(r).stream()).forEach(System.out::println);

    }
}
